﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

namespace GesturesViewer
{
    class ReadFile
    {
        String FILE_NAME = "C:\\Users\\Hyewon\\Desktop\\Mood Player\\GT_FSR_EXE\\State_Result_11_28_00_31_18.txt";
        DateTime lastModified;
        DateTime newlyModified;

        String realTimeEmotion = "";
        int NofNegative = 0;
        int NofNeutral = 0;
        int NofPositive = 0;
        int learnedEmotion; // 1 if Positive, 0 if Neutral, -1 if Negative

        public String ischanged()
        {
            Boolean changed = false;   //True : Changed, False : Not Changed   
            String test = "";

            FileInfo fi = new FileInfo(FILE_NAME);
            lastModified = newlyModified;
            newlyModified = fi.LastWriteTime;

            if (lastModified != newlyModified)
            {
                changed = true;
                Console.WriteLine("Chanaged: " + changed);
                Console.WriteLine("lastModified : " + lastModified);
                Console.WriteLine("newlyModified : " + newlyModified);
            }

            if (changed == true)
                test = read(FILE_NAME);

            return test;
        }

        public String read(String FilePath)
        {
            using (StreamReader sr = new StreamReader(FilePath))
            {
                while (!sr.EndOfStream)
                {
                    realTimeEmotion = sr.ReadLine();
                    if (sr.Peek() == -1)
                        return realTimeEmotion;
                }
            }
            return realTimeEmotion;
        }

        public int getLearnedEmotion()
        {
            if ((NofNegative > NofNeutral) && (NofNegative > NofPositive))
                learnedEmotion = -1; // Negative
            if ((NofNeutral > NofNegative) && (NofNeutral > NofPositive))
                learnedEmotion = 0; // Neutral
            if ((NofPositive > NofNeutral) && (NofPositive > NofNegative))
                learnedEmotion = 1; // Positive

            return learnedEmotion;
        }

    }
}
